package com.ruoyi.web.controller.pay;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.pay.entity.PayRefundOrder;
import com.ruoyi.pay.service.PayRefundOrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退款订单Controller
 *
 * @author ruoyi
 * @date 2020-10-10
 */
@Controller
@RequestMapping("/system/refundorder")
public class PayRefundOrderController extends BaseController
{
    private String prefix = "system/refundorder";

    @Autowired
    private PayRefundOrderService payRefundOrderService;

    @RequiresPermissions("system:order:view")
    @GetMapping()
    public String order()
    {
        return prefix + "/refundorder";
    }

    /**
     * 查询退款订单列表
     */
    @RequiresPermissions("system:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PayRefundOrder payRefundOrder)
    {
        startPage();
        List<PayRefundOrder> list = payRefundOrderService.list(Wrappers.query(payRefundOrder));
        return getDataTable(list);
    }

    /**
     * 导出退款订单列表
     */
    @RequiresPermissions("system:order:export")
    @Log(title = "退款订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PayRefundOrder payRefundOrder)
    {
        List<PayRefundOrder> list = payRefundOrderService.list(Wrappers.query(payRefundOrder));
        ExcelUtil<PayRefundOrder> util = new ExcelUtil<PayRefundOrder>(PayRefundOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 新增退款订单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存退款订单
     */
    @RequiresPermissions("system:order:add")
    @Log(title = "退款订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PayRefundOrder payRefundOrder)
    {
        return toAjax(payRefundOrderService.save(payRefundOrder));
    }

    /**
     * 修改退款订单
     */
    @GetMapping("/edit/{refundOrderId}")
    public String edit(@PathVariable("refundOrderId") String refundOrderId, ModelMap mmap)
    {
        PayRefundOrder payRefundOrder = payRefundOrderService.getById(refundOrderId);
        mmap.put("payRefundOrder", payRefundOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存退款订单
     */
    @RequiresPermissions("system:order:edit")
    @Log(title = "退款订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PayRefundOrder payRefundOrder)
    {
        return toAjax(payRefundOrderService.updateById(payRefundOrder));
    }

    /**
     * 删除退款订单
     */
    @RequiresPermissions("system:order:remove")
    @Log(title = "退款订单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(payRefundOrderService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
